<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    //
    public $table = 'dg_product';

    protected $fillable=['name','cate_id','image','content','price','desc','spec_type','store','attr','tip'];


    public function  getAttrAttribute($value)
    {
        if($value) {
            return json_decode($value,true);
        } else {
            return [];
        }

    }

    public function images()
    {
        return $this->hasMany('App\Models\ProductImage','product_id','id');
    }
     /**
     * 属于订单的的商品。
     */
    public function orders()
    {
        return $this->belongsToMany('App\Models\Order');
    }

    public function spu()
    {
        return $this->hasOne('App\Models\ProductSku','product_id','id');
    }
}
